/**
 * 
 */

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.furschina.dao.ArticleDao;
import com.furschina.model.Article;
import com.furschina.vo.ArticlePage;

/**
 * @author iday
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/spring-test.xml" })
public class ArticleDaoTestCase {
	@Autowired
	private ArticleDao dao;
	private List<Article> list = new ArrayList<Article>();
	private ArticlePage page;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		Article a = new Article();
		a.setTitle("衬衫+锥形裤 20款欧范复古潮搭");
		a.setSummary("【导语】初秋的第一抹气息袭击" +
				"申城，低头一看，一片红叶。静静的躺" +
				"在砖地上。她嘴角淡笑，慢慢的拾起，" +
				"夹在书里。行色匆匆的向地铁奔去。每" +
				"个秋天，每个女子必须要有一件开衫，" +
				"好比心里的那边红叶。");
		a.setContent("1.撞色假两件雪纺上衣开衫" +
				"大领口的盖领-首选！胸前的的螺纹" +
				"布防走光里衬---欲拒还迎！胸前两" +
				"个口袋---可以装零钱，炫富！两种" +
				"面料的拼接！想有点可爱，穿粉红的" +
				"，要知性选择黑色的，领口的鸡心，剪裁的很漂亮，");
		a.setPublishDate(new Date());
		dao.create(a);
		list.add(a);
		page = new ArticlePage();
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		dao.deleteAll(list);
		list.clear();
		page = null;
	}

	/**
	 * Test method for
	 * {@link com.furschina.dao.ArticleDao#search(com.furschina.vo.ArticlePage)}
	 * .
	 */
	@Test
	public void testSearchArticlePage() {
		page.setQ("衬衫");
		List<Article> list2 = dao.search(page);
		assertEquals(list.size(), list2.size());
		assertEquals(list.get(0).getSummary(), list2.get(0).getSummary());
	}

}
